<template>
  <div>
    <div>
      <el-form :inline="true">
        <!--        <el-form-item label="需求类型">-->
        <!--          <el-radio-group v-model="searchForm.status" @change="handleStatusChange">-->
        <!--            <el-radio-button :label="0">全部</el-radio-button>-->
        <!--            <el-radio-button :label="1">未处理</el-radio-button>-->
        <!--            <el-radio-button :label="2">已处理</el-radio-button>-->
        <!--          </el-radio-group>-->
        <!--        </el-form-item>-->
        <el-form-item label="筛选">
          <el-input v-model="searchForm.s" aria-placeholder="请输入手机号搜索" placeholder="请输入手机号搜索" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="handSearch">筛选</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div>
      <el-table v-loading="loading" border :data="tableData">
        <el-table-column label="姓名" prop="name" />
        <el-table-column label="手机号" prop="account.mobile" />
        <el-table-column label="入学时间" width="" prop="entrance_at" align="center" />
        <el-table-column label="所在年级" width="" prop="grade.grade_name" align="center" />
        <el-table-column label="班级" width="" prop="class_name" align="center" />
        <el-table-column label="登录时间" width="" prop="account.last_login" align="center" />
        <el-table-column label="操作" width="100">
          <template slot-scope="scope">
            <el-button type="success" @click="handleDelete(scope.row)">编辑</el-button>
          </template>
        </el-table-column>
      </el-table>

      <div>
        <el-pagination
          :current-page="paginator.page"
          :total="paginator.total"
          :page-size="paginator.limit"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </div>
  </div>
</template>

<script>
import { getList } from '../../api/student'
export default {
  data() {
    return {
      searchForm: {
        s: '',
        status: 0
      },
      tableData: [],
      loading: true,
      paginator: {
        total: 0,
        page: 1,
        limit: 10
      }
    }
  },
  mounted() {
    this.getList()
  },
  methods: {
    handleSizeChange(size) {
      this.paginator.limit = size
      this.getList()
    },
    handleCurrentChange(page) {
      this.paginator.page = page
      this.getList()
    },
    handleDelete(row) {
      console.log(row)
      this.$router.push({
        name: 'student-edit',
        params: {
          id: row.id
        }
      })
    },
    handSearch() {
      this.getList()
    },
    handleStatusChange(status) {
      console.log(status)
      this.searchForm.status = status
      this.getList()
    },
    getList() {
      this.loading = true
      getList({
        limit: this.paginator.limit,
        page: this.paginator.page,
        s: this.searchForm.s,
        status: this.searchForm.status
      }).then((res) => {
        console.log(res)
        this.tableData = res.data
        this.paginator.total = res.total
      }).finally(() => {
        this.loading = false
      })
    }
  }
}
</script>

